package com.yuwei.module_cash_desk
/**
 * 智慧园区-03-收银台-新增账单-V1.1-20250508-邓孟卓
 */
import android.app.DatePickerDialog
import android.app.TimePickerDialog
import android.widget.PopupMenu
import androidx.appcompat.view.ContextThemeWrapper
import com.alibaba.android.arouter.facade.annotation.Route
import com.blankj.utilcode.util.ToastUtils
import com.bw.lib_base.path.RouterPath
import com.bw.lib_common.view.BaseMvvmActivity
import com.yuwei.module_cash_desk.databinding.ActivityAddChargeBinding
@Route(path = RouterPath.MODULE_ADD_CHARGE_ACTIVITY)
class AddChargeActivity : BaseMvvmActivity<ActivityAddChargeBinding>() {
    override fun initViews() {
        super.initViews()
        binding.addChargeBack.setOnClickListener {
            finish()
        }
        binding.project.setOnClickListener {
            val contextThemeWrapper = ContextThemeWrapper(this, com.bw.lib_common.R.style.CustomPopupMenu)
            val popupMenu = PopupMenu(contextThemeWrapper,it)
            popupMenu.menuInflater.inflate(R.menu.charge_type_menu,popupMenu.menu)
            popupMenu.setOnMenuItemClickListener { item ->
                binding.chargeType.setText(item.title)
                false
            }
            popupMenu.show()
        }
        binding.start.setOnClickListener {
           DatePickerDialog(this,
                { _, year, month, dayOfMonth ->
                    val time = "${year}-${month+1}-${dayOfMonth}"
                    binding.startTime.setText(time)
                },2025,5,15).show()
        }
        binding.end.setOnClickListener {
            DatePickerDialog(this,
                { _, year, month, dayOfMonth ->
                    val time = "${year}-${month+1}-${dayOfMonth}"
                    binding.endTime.setText(time)
                },2025,5,15).show()
        }
        binding.sure.setOnClickListener {
            if(binding.chargeType.text.toString().isNullOrEmpty()){
                ToastUtils.showShort("类型不能为空")
                return@setOnClickListener
            }
            if(binding.startTime.text.toString().isNullOrEmpty()){
                ToastUtils.showShort("开始时间不能为空")
                return@setOnClickListener
            }
            if(binding.endTime.text.toString().isNullOrEmpty()){
                ToastUtils.showShort("结束时间不能为空")
                return@setOnClickListener
            }
            if(binding.newAddCount.text.toString().isNullOrEmpty()){
                ToastUtils.showShort("新增数量不能为空")
                binding.newAddCount.error = "新增数量不能为空"
                return@setOnClickListener
            }
            if(binding.totalMoney.text.toString().isNullOrEmpty()){
                ToastUtils.showShort("新增总金额不能为空")
                binding.totalMoney.error = "新增总金额不能为空"
                return@setOnClickListener
            }
            ToastUtils.showShort("添加成功")
            finish()
        }

    }
    override fun observeDataChange() {

    }

    override fun getLayoutId(): Int = R.layout.activity_add_charge

}